#include "c10_T1_bank.h"
#include <iostream>
#include <cctype>

const int N =5;
int n;
char ch;
double cash;

void main()
{
	//create an array of initialized objects
	BankAccount BA[N] =
	{
		BankAccount("Tingting You", "201402", 20.0),
		BankAccount("Zengchun Yang", "201501", 10.0),
		BankAccount("Lu Liu", "201502", 10.0),
		//BankAccount()
	};
	BankAccount temp("Jixuan Fu","201601",5.0);
	BA[N-1] = temp;

	std::cout << "Balance : \n";
	for (int i = 0; i < N; i++)
		BA[i].show();
	std::cout << "\nAll for the default information";

	std::cout << "Choose an account(enter the number), No._\b";
	while (!(std::cin >> n && (n-1)< N))
	{
		std::cin.clear();
		while (std::cin.get() != '\n')
			continue;
			std::cout << "Bad input, please enter again, Choose an account(enter the number), No._\b";
	}

	BA[n-1].show();

	std::cin.clear();
	while (std::cin.get() != '\n')
		continue;

	std::cout << "Enter D to deposit cash, enter W to withdraw cash, "
		<<"or Q to quit :_\b";
	while (std::cin >> ch && toupper(ch) != 'Q')
	{
		while (std::cin.get() != '\n')
			continue;
		if (!isalpha(ch))
		{
			std::cout << '\a';
			continue;
		}
		switch (ch)
		{
			case 'd':
			case 'D': 
				std::cout << "enter the cash acount to deposit : $";
				std::cin >> cash;
				BA[n - 1].deposit(cash);
				BA[n - 1].show();
				break;
			case 'w':
			case 'W':
				std::cout << "enter the cash acount to withdraw : $";
				std::cin >> cash;
				BA[n - 1].withdraw(cash);
				BA[n - 1].show();
				break;
			default: 
				std::cout << "\a";
				break;
		}
		std::cout << "Enter D to deposit cash, enter W to withdraw cash, "
			<< "or Q to quit :_\b";
	}

	system("pause");
}
